package com.hc.kotlin

fun main() {
    var l = Leg()
    println( l.move())
    var c = Car("I am benchi")
    println(c.move())
    var t = TClass("Hello")
    var f:(String)->String ={
        it
    }
    println(t.f1(f))
    var t2 = TClass(18)
    val t2f1 = t2.f1 {
        it + 10
    }
    println(t2f1)
}

interface Vehicle{ //接口
    var name:String
    val foot:Int
        get() = -1
    fun move():String
}
class Leg():Vehicle{
    override var name: String //属性和方法重写必须加override关键字
        get() = "I am Leg"
        set(value) {}
    override val foot: Int
        get() = 2

    override fun move(): String {
        return "${name} ,  moving by ${foot} foot"
    }
}
class Car(override var name: String):Vehicle,Gun(){
    override var foot: Int
        get() {
            return 4
        }
        set(value) {}

    override fun move(): String {
        return "${name} ,  moving by ${foot} foot"
    }

    override fun shot(): String {
        return "Car is shoting"
    }
}
abstract class Gun(){ //抽象类
    fun add():String{
        return "adding"
    }
    abstract fun shot():String
}
class TClass<T>(var t:T){ //泛型
    fun <R> f1(f:(T)->R):R{
        return f(t)
    }
}
class TClass1<T:Vehicle>(var t:T){ //泛型约束
    fun <R> f1(f:(T)->R):R{
        return f(t)
    }
    fun f2(vararg a:T){ //不定长参数+泛型
        var b: Array<out T> = a //接收a
        var c = b[0]
        println(c)
    }
}